﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="Checkbox.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011 
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.GUI.
//
//   It is released under the Microsoft Public License (Ms-PL).
//
//   You should have received a copy of the Microsoft Public License
//   along with starLiGHT.GUI. If not, see http://sle.codeplex.com/license.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.GUI are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 9631                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-05-03 11:00:42 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.GUI.Widgets
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

    public class Checkbox : ButtonBase, ICheckable
    {
        private bool isChecked;

        #region Constructors
        public Checkbox(GuiManager manager, string name)
            : base(manager, name)
        {
        }

        public Checkbox(GuiManager manager, string name, string layout)
            : base(manager, name, layout)
        {
        }
        #endregion

        #region Events
        public event EventHandler Click;

        public event EventHandler CheckChanged;

        #endregion

        public bool Checked
        {
            get 
            {
                return this.isChecked; 
            }

            set
            {
                if (value != this.isChecked)
                {
                    this.isChecked = value;
                    SetState(value ? "Checked" : "Normal");
                    this.OnCheckChanged(this, new EventArgs());
                }
            }
        }

        public override bool CanFocus
        {
            get
            {
                return true;
            }
        }

        public override void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (!e.WidgetUnderMouse)
            {
                return;
            }

            base.OnMouseUp(sender, e);

            OnClick(this, e);

            this.Checked = !this.Checked;
            ////if (this.Checked)
            ////{
            ////    SetState("Normal");
            ////    this.Checked = false;
            ////}
            ////else
            ////{
            ////    SetState("Checked");
            ////    this.Checked = true;
            ////}

            ////this.OnCheckChanged(this, e);
        }

        public void OnCheckChanged(object sender, EventArgs e)
        {
            if (this.CheckChanged != null)
            {
                this.CheckChanged(sender, e);
            }
        }
    }
}
